/*
 * Created on Jun 29, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.vectrics.recruiter.job.event;

import java.util.Locale;

import org.vectrics.common.html.Cell;
import org.vectrics.event.Event;
import org.vectrics.event.EventEmailBuilder;
import org.vectrics.mail.EmailHtmlBase;
import org.vectrics.mail.MailMessage;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.JobCandidate;

/**
 * @author MMoore
 */
public class JobCandidateEmailBuilder extends EventEmailBuilder {
	private JobCandidate jobCandidate = null;
	
	/**
	 * 
	 */
	public JobCandidateEmailBuilder(Event event, JobCandidate jobCandidate, Locale locale) {
		super(event, locale);
		this.jobCandidate = jobCandidate;
	}
	
	protected String getEmailFromName() {
		String from = CoreServiceLocator.getSystemService()
			.getStringSystemConstant("mail.from.name", jobCandidate.getJob().getDomain());
		return(from);
	}
	
	protected void renderContent(Cell cell) {
		
	}
	
	public boolean supportsHtml() {
		return(true);
	}

	public MailMessage getTextMailMessage() {
		MailMessage message = new MailMessage(jobCandidate.getJob().getDomain());
		message.setContentType(MailMessage.CONTENT_TEXT);
		message.setBody("This job candidate was created: " 
				+ jobCandidate.getCandidate().getPerson().getName());
		message.setFromName(this.getEmailFromName());
		message.setSubject(this.getSubject());
		return(message);
	}
	
	
	
	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#createHtmlEmail()
	 */
	protected EmailHtmlBase createHtmlEmail() {
		JobCandidateHtmlEmail email = new JobCandidateHtmlEmail(this.getDomain(), this.getLocale(), this.jobCandidate);
		return(email);
	}

	
	public String getSubject() {
		String subject = "Error: don't know how to make subject for event type: " + this.getEvent().getEventType().getCode(); 
		
		String eventTypeCode = this.getEvent().getEventType().getCode().trim();
		if (eventTypeCode.equals("job.candidate.sts.chg")) {
			subject = this.getPhrase("email.subject.job.candidate.status.changed") + ": "  + 
			this.jobCandidate.getJob().getTitle() + " (" + this.jobCandidate.getCandidate().getPerson().getName() + ")";
		} else if (eventTypeCode.equals("job.candidate.created")) {
			subject = this.getPhrase("email.subject.job.candidate.created") + ": "  + 
			this.jobCandidate.getJob().getTitle() + " (" + this.jobCandidate.getCandidate().getPerson().getName() + ")";
		}
		return(subject);
	}
}
